﻿
using ManagementTool.DB.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManagementTool.DB.Sql
{
    public class SqlsControl
    {
        public string GetCreatDeviceInfoDBSql(string _tabName)
        {
            string sql = string.Format("CREATE TABLE IF NOT EXISTS {0}(id INT NOT NULL AUTO_INCREMENT,SoftName VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,IPAddress VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,Port VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,PcSign VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,State INT," +
                                        "CurrentVersion VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,CurrentOperationType INT,CurrentOperationResultTypee INT," +
                                        "LoginTime datetime NULL,PRIMARY KEY (id));", _tabName);
    
            return sql;
        }

        public string GetCreatFileInfoDBSql(string _tabName)
        {
            string sql = string.Format("CREATE TABLE IF NOT EXISTS {0}(id INT NOT NULL AUTO_INCREMENT,FileName VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,FilePath VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci,FileVersion VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci," +
                                        "FileUpdateTime datetime NULL,PRIMARY KEY (id));", _tabName);
      
            return sql;
        }


        public string GetDeviceInfoDBCountSql()
        {
            string sql = $"SELECT COUNT(id)  FROM deviceencryinfo";
         
            return sql;
        }

        public string GetDeviceInfoDBSql(int inputpageCode, int inputPageSize)
        {
            string sql = $"SELECT * from deviceencryinfo ";
            sql += "ORDER BY id  limit " + +(inputpageCode - 1) * inputPageSize + "," + inputPageSize;
        
            return sql;
        }

        public string GetAnyDevItemSql(string _PcSign)
        {
            string sql = $"SELECT id FROM deviceinfo WHERE PcSign='{_PcSign}';";
        
            return sql;
        }

     

        public string GetUpdateDevCurrentOperationTypeSql(string _PcSign, int _CurrentOperationType)
        {
            string sql = $"UPDATE deviceinfo SET CurrentOperationType={_CurrentOperationType} WHERE PcSign='{_PcSign}';";
     
            return sql;
        }

      

        public string GetInstertFileISql(CommonExtenControl.Model.FileModel item)
        {
            string sql = $"insert FileInfo (FileName,FilePath,FileVersion,FileUpdateTime)" +
            $"values('{item.FileName}','{item.FilePath}','{item.FileVersion}','{item.FileUpdateTime}')";

            string _sql = sql.Replace("\\", "\\\\");
   
            return _sql;
        }

        public string GeFileInfoDBSql(int inputpageCode, int inputPageSize)
        {
            string sql = $"SELECT * from fileinfo ";
            sql += "ORDER BY FileUpdateTime  limit " + +(inputpageCode - 1) * inputPageSize + "," + inputPageSize;
         
            return sql;
        }
    }
}
